import { ADD, MINUS } from './constant'

// 创建为Count组件服务的reducer, reducer本质是一个函数
// reducer函数会接到两个参数 之前的状态preState 动作对象action

// 初始化state
const initState = 0;

export default function countReducer(preState = initState, action) {
    // console.log(preState, action);
    const {type, data} = action;
    // 根据type决定如何加工数据
    switch (type) {
        case ADD:
            return preState + data;
        case MINUS:
            return preState - data;
        default:
            return preState;
    }
}